package com.cai.quartz.job;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;

import java.util.Date;

@Slf4j
public class MyJob implements Job {
    @Setter
    private String name;

    @Override
    public void execute(JobExecutionContext jobExecutionContext){
        log.debug("当前时间：{}",new Date());
        log.info("执行任务【服务任务1】");
        //获取JobDetail的内容
        JobKey key = jobExecutionContext.getJobDetail().getKey();
        log.info("工作任务名称："+key.getName()+" 工作任务组："+key.getGroup());
        log.info("任务类名称："+jobExecutionContext.getJobDetail().getJobClass().getName());

        //从jobDetail对象中获取jobDataMap数据
        JobDataMap jobDetailDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        log.info("任务数据的参数值："+jobDetailDataMap.getString("name"));
        //从Trigger对象中 获取jobDataMap数据
        JobDataMap triggerDataMap = jobExecutionContext.getTrigger().getJobDataMap();
        log.info("触发器数据的参数值："+triggerDataMap.getString("name"));
        TriggerKey triggerKey = jobExecutionContext.getTrigger().getKey();
        log.info("触发器名称："+triggerKey.getName()+" 触发器组名："+triggerKey.getGroup());

        //获取其他信息
        log.info("当前任务的执行时间："+jobExecutionContext.getFireTime());
        log.info("当前任务的下次执行时间："+jobExecutionContext.getNextFireTime());

        //读取name usingJobData("name","兔子猫")  usingJobData("name","蔡志强") 如果有同名的Trigger会覆盖jobDetail
        System.out.println("触发器："+name);
    }
}
